<#assign module="car" />
<@override name="header">
<link rel="stylesheet" href="${ctx}/assets/css/datetimepicker.css">
<link rel="stylesheet" href="${ctx}/assets/css/jquery.Jcrop.css">
</@override>
<@override name="body">
	<#--<div class="row">
		<div class="col-md-12">
			<div class="panel panel-default">
				<div class="panel-heading">上传汽车图片（可选）</div>
				<div class="panel-body">
					<div style="float:left;width:200;margin-right:8px;">
                        <button href="" class="btn btn-primary" id="photo_upload_zhuche_car">上传汽车图片</button>
                        <input type="file" id="zhuche_img_up" name="zhuchepicture" style="display: none;">
                        <p></p>
						<div id="show_photo_div">
						    <img id="show_photo" class="img-responsive" width="100%" height="200px"/>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>-->


	<div class="row">
		<div class="col-md-12">
			<form id="submit_form" action="${ctx}/car/create" class="form-horizontal" role="form" method="post">
				<input type="hidden" id="id" name="id" >
				<input type="hidden" id="purpose" name="purpose" value="0">
				<input type="hidden" id="picture" name="picture" >
					<div class="panel panel-default margin-top">
						<div class="panel-heading">基本信息</div>
							<div class="panel-body">
							
								<div class="col-md-6">
								
									
								<#--	<div class="form-group">
								        <label class="col-sm-3 control-label"><em>*</em>品牌:</label>
								        <div class="form-group">
									        <div class="col-sm-4">
									            <select class="form-control" name="brandId" id="brandId" required>
									            <option value="" selected="selected" >---请选择---</option>
													<#if listBrand?? >
														<#list listBrand as brand>
										  					<option value="${brand.id}" >${brand.name}</option>
										  				</#list>
									  				</#if>
											  	</select>
											</div>
										</div>
								    </div>-->
								    
								   
								    <div class="form-group">
								        <label class="col-sm-3 control-label"><em>*</em>名称:</label>
								        <div class="form-group">
										    <div class="col-sm-4">
										      <input type="text" class="form-control" id="name" name='name'  placeholder="输入车辆名称" required>
										    </div>
									  	</div>
								    </div>
								    
								    	<@shiro.isMainCompany>
										<div class="form-group">
									        <label class="col-sm-3 control-label"><em>*</em>所属公司:</label>
									        <div class="form-group">
										        <div class="col-sm-4">
													<select class="form-control" name="companyId" id="companyId" required>
														<option value="">请选择所属公司</option>
											  			<#list company as c>
											  				<option value="${c.id}" >${c.abbreviation}</option>
											  			</#list>
										  			</select>
									  			</div>
								  			</div>
									    </div>
								    </@shiro.isMainCompany>	
								    
								    <div class="form-group">
								        <label class="col-sm-3 control-label"><em>*</em>门店:</label>
								        <div class="form-group">
									        <div class="col-sm-4">
									        	<select class="form-control" name="shopId" id="shopId" required>
									        	<option value="" selected="selected" >请选择门店</option>
										        	<#if listShop ?? >
											        	<#list listShop as shop>
											        		<option value="${shop.id}" >${shop.shopName}</option>
											        	</#list>
										        	</#if>	
												</select>
								  			</div>
							  			</div>
								    </div>
								    
								    <div class="form-group">
								        <label class="col-sm-3 control-label"><em>*</em>车牌号:</label>
								        <div class="form-group">
										    <div class="col-sm-4">
										      <input type="text" class="form-control" id="carNumber" name="carNumber" required />
										    </div>
									  	</div>
								    </div>
								    
								  <#--  <div class="form-group">
								        <label class="col-sm-3 control-label"><em>*</em>汽车类型:</label>
								        <div class="form-group">
									        <div class="col-sm-4">
									            <select class="form-control" name="carTypeId" id="carTypeId" required>
													<option value="">---请选择---</option>
														<#if listCarType ?? >
															<#list listCarType as c>
											  					<option value="${c.id}" >${c.name}</option>
											  				</#list>
										  				</#if>
											  	</select>
											</div>
										</div>
								    </div>
								    
								    <div class="form-group">
								        <label class="col-sm-3 control-label"><em>*</em>座位数:</label>
								        <div class="form-group">
									        <div class="col-sm-4">
									            <div class="input-group">
												  <input type="number" class="form-control" id="seating" name="seating"  placeholder="请输入2~32范围内的座位数" required>
												  <span class="input-group-addon">座</span>
												 </div>
											</div>
										</div>
								    </div>
								    <div class="form-group">
								        <label class="col-sm-3 control-label"><em>*</em>车型:</label>
								        <div class="form-group">
										    <div class="col-sm-4">
										      <input type="text" class="form-control" id="type" name="type" required/>
										    </div>
										    <div class="col-sm-8 help-block">
											      <label style="margin-left:240px;margin-top:3px;">如:二厢,三厢,SUV,紧凑型车,中型车</label>
										    </div>
									  	</div>
								    </div>-->
								</div>
								
								<div class="col-md-6">
									<#--<div class="form-group">
								        <label class="col-sm-3 control-label"><em>*</em>排量:</label>
								        <div class="form-group">
										    <div class="col-sm-4">
										    <#--	<!--<div class="">-->
											<#--	     <input type="text" class="form-control" id="displacement" name="displacement" placeholder="如:1.8T或	2.4L" required/>
										    	<!--</div>-->
										  <#--  </div>
									  	</div>
								    </div>
									<div class="form-group">
								        <label class="col-sm-3 control-label"><em>*</em>状态:</label>
								        <div class="form-group">
									        <div class="col-sm-4">
									        	<select class="form-control" name="status" id="status" required>
													<option value="1" <#if car.status?? && car.status==1>selected="selected"</#if>>空闲</option>
												  	<option value="0" <#if car.status?? && car.status==0>selected="selected"</#if>>忙碌</option>
												</select>
											</div>
										</div>
								    </div>-->
								    <div class="form-group">
								        <label class="col-sm-3 control-label"><em>*</em>已行驶:</label>
								        <div class="form-group">
									        <div class="col-sm-4">
												  <input class="form-control" id="drivingDistance" name="drivingDistance" type="text"  required/>
											</div>
									           <#--  <div class="input-group">
												  <input type="number" class="form-control" id="drivingDistance" name="drivingDistance" required>
												 <span class="input-group-addon">公里</span>
												 </div>-->
										</div>
								    </div>
								    <div class="form-group">
								        <label class="col-sm-3 control-label"><em>*</em>购置时间:</label>
								        <div class="form-group">
									        <div class="col-sm-4">
												  <input class="form-control" id="buyTime" name="buyTime" type="text"  required readonly/>
											</div>
										</div>
								    </div>
								    <div class="form-group">
								        <label class="col-sm-3 control-label"><em>*</em>是否限行:</label>
								        <div class="form-group">
									        <div class="col-sm-4">
									            <select class="form-control" name="limitLine" id="limitLine" required>
													<option value="0" <#if car.limitLine?? && car.limitLine=="0">selected="selected"</#if>>不限行</option>
											  		<option value="1" <#if car.limitLine?? && car.limitLine=="1">selected="selected"</#if>>周一限行</option>
											  		<option value="2" <#if car.limitLine?? && car.limitLine=="2">selected="selected"</#if>>周二限行</option>
											  		<option value="3" <#if car.limitLine?? && car.limitLine=="3">selected="selected"</#if>>周三限行</option>
											  		<option value="4" <#if car.limitLine?? && car.limitLine=="4">selected="selected"</#if>>周四限行</option>
											  		<option value="5" <#if car.limitLine?? && car.limitLine=="5">selected="selected"</#if>>周五限行</option>
								  				</select>  
											</div>
										</div>
								    </div>
							     <#--   <div class="form-group" >
								        <label class="col-sm-3 control-label"><em>*</em>变速箱:</label>
								        <div class="col-sm-6">
								        	<div class="col-sm-6">
									        	<label class="radio">
												  <input type="radio" name="transmissionCase" value="AT" <#if car.transmissionCase?? && car.transmissionCase=='AT'>checked="checked"</#if> />自动挡
												</label>
								        	</div>
											<div class="col-sm-6">
									        	<label class="radio">
												  <input type="radio" name="transmissionCase" value="MT" <#if car.transmissionCase?? && car.transmissionCase=='MT'>checked="checked"</#if> />手动挡
												</label>
								        	</div>
										</div>
								    </div>
								    
								    <@zu>
								    <div class="form-group">
								        <label class="col-sm-3 control-label"><em>*</em>价格:</label>
								        <div class="form-group">
									        <div class="col-sm-4">
									            <div class="input-group">
												  <input type="number" class="form-control" name="price" id="price" min="0" required/>
												  <span class="input-group-addon">元/天</span>
												</div>
											</div>
										</div>
								    </div>
								    <div class="form-group">
								        <label class="col-sm-3 control-label"><em>*</em>押金:</label>
								        <div class="form-group">
									        <div class="col-sm-4">
									            <div class="input-group">
												  <input type="number" class="form-control" name="deposit" id="deposit" min="0" required/>
												  <span class="input-group-addon">元/次</span>
												</div>
											</div>
										</div>
								    </div>
								    </@zu>-->
								</div>
						<#--	<div class="col-md-12">
									<div class="form-group">
								        <label class="col-sm-2 control-label" style="margin-left:128px;width:100px;"><em>*</em>所在地:</label>
								        <div class="col-sm-2" >
									        <select id="provincial" class="form-control" name="provincial" required></select>
										</div>
								        <div class="col-sm-2" >
									        <select id="city"  class="form-control" name="city" required></select>
										</div>
								        <div class="col-sm-2" >
									        <select id="county" class="form-control" name="county" required></select>
										</div>
								        <div class="col-sm-2">
								        	<input type="text"  class="form-control" id="place" name="place"  required>
									    </div>
								   </div>
							</div>-->
							<div class="row">

     					 
							<div class="col-md-12" style="margin-top:20px;">
								<div class="col-md-2">
								 <input type="text" class="form-control" id="vehicle" name='vehicle'  placeholder="车系" required>
				  				</div>
				  				<div class="col-md-3">
				  				<button  id="searchButton" class="btn btn-primary" type="button">检索</button>
				  				</div>
			  				</div>
							<div class="col-md-12" style="margin-top:20px;">
								<table class="table table-hover table-striped">
								<tbody>
										<tr style="font-size:14px;">
											<th>车系</th>
											<th>租金</th>
											<th>押金</th>
											<th>品牌</th>
											<th>变速箱</th>
											<th>车型</th>
											<th>排量</th>
											<th>座位数</th>
											<th>操作</th>
										</tr>
									</tbody>
								</table>
								<br>
								<div style="text-align:center" id="NoData"></div>
								</br>
								<ul class="pagination pull-left pagination-sm pageshow" style="display:none;">
									<li><a></a></li>
								</ul>
								<ul class="pagination pull-left pagination-sm pagedata" style="display:none;">
    							</ul>
							</div>
							<div class="col-md-12" style="margin-top:20px;">
								<div class="col-md-5">
								</div>
								<div class="col-md-4">
									<div class="form-group">
				        				<input type="submit" id="submit_button" class="btn btn-primary" value="保存">
				  					<span>&emsp;&emsp;</span>
					        			<input type="button" class="btn btn-default" onclick="window.location.href = '${ctx}/car/list';" value="返回">
					  				</div>
				  				</div>
			  				</div>
							</div>
				</div>
			</form>
		</div>
	</div>

	
<#--	<div id="dialog_local_photo" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
		<div class="modal-dialog modal-lg" >
			 <div class="modal-content">
			 	<div class="modal-header">
	        		<button type="button" class="close close_modal" data-dismiss="modal" aria-hidden="true">&times;</button>
	        		<h4 class="modal-title">汽车图片上传</h4>
	      		</div>
	      		<div class="modal-body" >
	      			<div class="row" >
	      				<div class="col-xs-6">
	      					<div class="form-group">
					      		<div class="caption" style="height:40px;">
							        <p>
								        <button href="javascript:;" class="btn btn-primary" id="photolocalsnap">本地上传</button>
								        <input style="display:none;" type="file" name="pic1" id="photoFile" accept=".bmp,.gif,.jpeg,.jpg,.png">
								    </p>
							    </div>
					            <canvas id="photoCanvas" width="400" height="200" style="display:none;"></canvas>
							    <div id="photoImg_div" style="width:400px;height:400px;display:table-cell;text-align:center;">
							    	
							    </div>
					        </div>
	      				</div>
	      				
	      				<div class="col-xs-6" style="height:0px;">
		        			<div id="photoImg_container" style="width:400px;height:200px;overflow:hidden;margin-top:40px;">
		        		
		        			</div>
		        		</div>
		        		
		        		<div class="col-xs-12">
					      	<div class="form-group">
					      		<div class="caption">
							        <p>
								        <button href="javascript:;" id="photo_ok" class="btn btn-primary">确认</button>
							        </p>
							    </div>
					        </div>
				        </div>
				        
	      			</div>
	      		</div>
			 </div>
		</div>
	</div>-->
</@override>
<@override name="footer">
<script src="${ctx}/assets/js/region_select.js"></script>
<script src="${ctx}/assets/js/bootstrap-datetimepicker.min.js"></script>
<script src="${ctx}/assets/js/bootstrap-datetimepicker.zh-CN.js"></script>
<script src="${ctx}/assets/js/ajaxfileupload.js"></script>
<script src="${ctx}/assets/js/carcamera.js"></script>
<script src="${ctx}/assets/js/swfobject.js"></script>
<script src="${ctx}/assets/js/jquery.Jcrop.js"></script>
<script type="text/javascript">
		$("#searchButton").click(function(){
		 $.scojs_message("检索", $.scojs_message.TYPE_ERROR);
		});
		
	$(document).ready(function(){
		$("input[type='number']").bind("input propertychange",function(){
            if(!/^[0-9]+.?([0-9]{1,2})?$/.test($(this).val())){
                $(this).val("");
                $.scojs_message("请输入正确的值", $.scojs_message.TYPE_ERROR);
				return;
            }
            if(isNaN($(this).val()) || $(this).val()==""){
				$(this).val("");
                $.scojs_message("请输入正确的值", $.scojs_message.TYPE_ERROR);
			}
		});
		$("#displacement").bind("input propertychange",function(){
			var val = $(this).val();
			if(val != "" && val != null){
				val = val.toUpperCase();
			}
            if(!/^[0-9]+\.?([0-9]{1})?(T?|L?)$/.test(val)){
                $(this).val("");
                $.scojs_message("请输入正确的值", $.scojs_message.TYPE_ERROR);
				return;
            }
		});


		//品牌与品牌类型联动
		$("#brandId").bind('change',function(){
		
			var params={id:$("#brandId").val()}
			$.post('${ctx}/car/chooseBrandType',params,function(object){
				$("#brandTypeId").empty();
				if(object.success){
					$(object.data).each(function(index,data){
						var option = "<option value='"+data.id+"'>"+data.name+"</option>";
						$("#brandTypeId").append(option);
					});
				}else{
					$("#brandTypeId").append("<option>"+object.message+"</option>");
				}
			});
		
		});
		
		//省、市、县
		new PCAS('provincial','city','county');
		
		<#if car.provincial??>
			$("#provincial option").each(function(index,element){
			  	if($(element).attr("value")=="${car.provincial}"){
			 		$(element).attr("selected","selected");
			 		$(element).change();
			 		return false;
			 	}
			});
		</#if>
		
		<#if car.city??>
			$("#city option").each(function(index,element){
			  	if($(element).attr("value")=="${car.city}"){
			 		$(element).attr("selected","selected");
			 		$(element).change();
			 		return false;
			 	}
			});
		</#if>
		
		<#if car.county??>
			$("#county option").each(function(index,element){
			  	if($(element).attr("value")=="${car.county}"){
			 		$(element).attr("selected","selected");
			 		return false;
			 	}
			});
		</#if>
			
		$("#seating").change(function(){
			var seatNumber=$("#seating").val();
			if(parseInt(seatNumber)<2 || parseInt(seatNumber)>32){
				$.scojs_message("请填写正确的座位数(座位数在2~32范围内)", $.scojs_message.TYPE_ERROR);
			}
		});
		
		//初始化
		
		$(function () {

			if($("#buyTime").length>0){
				$("#buyTime").datetimepicker({ format: 'yyyy-mm-dd', language: 'zh-CN', minView: 'month', pickDate: true, pickTime: false, inputMask: false, autoclose: true ,endDate:new Date()});
			}
		});
		
		//提交表单
		$("#submit_form").submit(function(){
			var carNumber = $("#carNumber").val();
			var val = $("#displacement").val();
            $("#displacement").val(val.toUpperCase());
			if(!carNumber.trim()){
	  			$.scojs_message("请输入车牌号码", $.scojs_message.TYPE_ERROR);
	  			return false;
	  		} else {
	  			if(!(/^([\u4e00-\u9fa5]{1}[A-z]{1}[A-z_0-9]{5,10})$/.test(carNumber))){
	  				$.scojs_message("车牌号码格式不正确", $.scojs_message.TYPE_ERROR);
	  				return false;
	  			}
	  		}
			
			var companyId=$("#companyId").val();
			if(companyId==""){
				$.scojs_message("请选择所属公司", $.scojs_message.TYPE_ERROR);
				$("#companyId").focus();
				return false;
			}
		
			if($("#price").val()==""){
				$.scojs_message("请填写价格", $.scojs_message.TYPE_ERROR);
				$("#price").focus();
				return false;
			}
			
			if($("#deposit").val()==""){
				$.scojs_message("请填写押金", $.scojs_message.TYPE_ERROR);
				$("#deposit").focus();
				return false;
			}
			
	   		$.post($("#submit_form").attr("action"),$("#submit_form").serialize(),function(result){
				if(result.success){
					window.location="${ctx}/car/list";
				}
				else{
					$.scojs_message(result.message, $.scojs_message.TYPE_ERROR);
				}
			});
			return false;
		});
	
	});
</script>
</@override>
<@extends name="../layout.ftl"/>
